package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.baoding.api.bean.BuyCartRet
import client.comm.baoding.ui.viewmodel.MiddleVm

class BuyCartModel(app: Application) : MiddleVm(app) {

    val isShowing = MutableLiveData<Boolean>(false)

    val isCheckAll = MutableLiveData<Boolean>(false)
    val isEditMode = MutableLiveData<String>("编辑")
    val isEditModeVal = MutableLiveData<Boolean>(true)

    val callBuyCart = MutableLiveData<JsonResult<BuyCartRet>>()
    val delRet = MutableLiveData<JsonResult<Ret>>()

    fun callBuyCart() {
        hold({
            server.shopping_cart()
        }, {
        }, {
            callBuyCart.value = it
        })
    }

    fun delCart(list: ArrayList<BuyCartRet.Shopping>) {
        hold({
            var goods_sku_idS = ""
            for (i in list) {
                goods_sku_idS += "${i.shopping_id},"
            }
            server.del_shopping_cart(goods_sku_idS)
        }, {
            isShowing.value = true
        }, {
            delRet.value = it
        }, complete = {
            isShowing.value = false
        })
    }

}